<template>
	<view>
		<f-navbar title="修改密码"></f-navbar>
		<view class="modify-password">
			<view class="form">
				<view class="form-item l-border-bottom">
					<u-input color="#000000" fontSize="28rpx" placeholderStyle="color:#BBBBBB;font-size:28rpx;"
						placeholder="请输入新密码" border="none" maxlength="20" password v-model="form.password"></u-input>
				</view>
				<view class="form-item">
					<u-input color="#000000" fontSize="28rpx" placeholderStyle="color:#BBBBBB;font-size:28rpx;"
						placeholder="请再次输入新密码" border="none" maxlength="20" password v-model="form.rpassword">
					</u-input>
				</view>
			</view>
			<view class="login-btn">
				<u-button color="linear-gradient(83deg, #48B453 0%, #2C9F79 100%)"
					:customStyle="{width:'610rpx',height:'80rpx',fontSize:'32rpx',borderRadius:'50rpx',fontWeight:'bold'}"
					@click="submitForm">确认修改
				</u-button>
			</view>
		</view>
	</view>

</template>

<script>
	import {updatePassword} from "@/api/login.js"
	export default {
		data() {
			return {
				form: {
					password: null,
					rpassword: null
				}
			};
		},
		methods: {
			submitForm(){
				if (!this.form.password) {
					uni.$u.toast('请输入新密码');
				} else if (this.form.password.length < 6 || this.form.password.length > 20) {
					uni.$u.toast('密码设置需要在6-20位之间');
				} else if (!this.form.rpassword) {
					uni.$u.toast('请再次输入新密码');
				} else if (this.form.password != this.form.rpassword) {
					uni.$u.toast('两次密码输入不一致');
				} else {
					updatePassword({
						password: this.form.password
					}).then((res) => {
						uni.$u.toast('修改成功，请重新登录！');
						this.$store.commit('setUserInfo', null);
						setTimeout(() => {
							uni.reLaunch({
								url:'/pages/login/index'
							})
						}, 1000)
					})
				}
			}
		},
	};
</script>

<style lang="scss" scoped>
	.modify-password {
		.form {
			margin-top: 30rpx;
			padding: 0 30rpx;
			background: #fff;
		}

		.form-item {
			padding: 30rpx 0;
			border-bottom: 1rpx solid #EFEFEF;
			display: flex;
			align-items: center;

			&:last-child {
				border: none;
			}

			.codeText {
				font-size: 28rpx;
				color: #138e57;
			}
		}

		.login-btn {
			margin-top: 80rpx;
		}
	}
</style>